<template>
  <div class="components-container">
    <div class="header-form">
      <div class="layui-inline">
        <label class="layui-form-label" >厂家名称</label>
         <div class="layui-input-inline">
            <el-select v-model="selectData.VdrnameLike" placeholder="请选择厂家">
              <!-- <el-option label="全部" :value="null"></el-option> -->
              <el-option v-for="item in chargeProjectTypes" :key="item.CodeValue" :label="item.CodeName" :value="item.CodeValue"/>
            </el-select>
         </div>
      </div>
     <!-- <div class="layui-inline">
        <label class="layui-form-label" >项目状态</label>
         <div class="layui-input-inline">
        <el-select v-model="selectData.chastatusEqual" placeholder="请选择项目状态">
          <el-option label="全部" :value="null"></el-option>
          <el-option v-for="item in chaStatusTypes" :key="item.value" :label="item.label" :value="item.value">
          </el-option>
        </el-select>
         </div>
      </div>
      <div class="layui-inline">
        <label class="layui-form-label" >项目名称</label>
         <div class="layui-input-inline">
            <el-input  v-model="selectData.nameLike" placeholder="请输入辖区"></el-input>
         </div>
      </div> -->
      <el-button type="primary"  @click="btnSearch" :loading="this.$store.state.isloading">搜索</el-button>
      <el-button  @click="btnRepeat">重置</el-button>
    </div>
    <div>
      <ul class="toolList">
        <li><el-button type="primary" @click="btnSearch" :loading="this.$store.state.isloading">刷新</el-button></li>
        <li v-if="btnShow(item.BTNVALUE)" v-for="(item, index) in $store.state.btnListCommon" @click="operate(item.BTNVALUE)">
          <el-button type="primary" :value="item.BTNSHOWNAME" v-text="item.BTNSHOWNAME"></el-button>
        </li>
      </ul>
    </div>
    <dataTable :headList="headList" :dataList="dataList" :pageOrder="pageOrder" @pageChange="pageChange" @selectRow="selectRow"></dataTable>

    <manufactorMaintainmain ref="dialog" :orderType="order" @refreshData="getData"></manufactorMaintainmain>
    <staEndUse ref="useMain" @refreshData="getData"></staEndUse>
  </div>
</template>
<style rel="stylesheet/scss" lang="scss" scoped>
@import "src/styles/common.scss";
.el-button + .el-button {
  margin-left: 0;
}
.btnCenter {
  text-align: center;
}
</style>
<script>
import sweetModal from "@/components/sweetModal";
import manufactorMaintainmain from "./manufactorMaintainmain";
import dataTable from "@/components/Table/DataTable";
import apiBase from "@/api/apiBase.js";
import { formatDate, timeStringToDate } from "@/utils/date.js";
import staEndUse from "../basic/staEndUse";
import { ORDER } from "@/const/orderConst.js";
import { manage } from "@/mixins/managePage.js";


const ADD = "新增";
const MODIFYPROJECT = "修改";
const DELETE = "删除";
const INFO = "详情";
const enable = "启用";
const disable = "禁用";

export default {
  name: "chargeProjectManage",
  mixins: [manage],
  data() {
    return {
      title: null,
      loading: false,
      chargeProjectTypes: [],
      chaStatusTypes: [],
      chaReductionTypes: [],
      chaUintsTypes: [],

      selectData: {
          VdrnameLike: null,
      },
      chaData: {},

      //价格历史
      dataListLSJG: [],
      headListLSJG: [],
      //分页和排序
      pageOrderLSJG: {
        orderType: null,
        orderSort: null,
        totalNum: null,
        pageSize: 10,
        currentPage: 1
      },
      sweetModalWidth: 80,
      sweetModalMaxWidth: 840,
      hiddenColumn: false
    };
  },
  methods: {
    //收费项目查询
    getData() {
      let data = {
        PageIndex: this.pageOrder.currentPage,
        PageSize: this.pageOrder.pageSize,
        OrderBy: this.pageOrder.orderType,
        OrderByType: this.pageOrder.orderSort,
        // Data: JSON.parse(JSON.stringify(this.selectData))
      };
      apiBase.DoService(
        data,
        apiBase.getApiAdress().Depot.QueryVdr,
        res => {
          this.dataList = res.data.content.OutData;
          this.pageOrder.totalNum = res.data.content.RecordCount;
        },
        res => {
          this.$message.error(res.data.msg);
        }
      );
    },
    //获取表头
    getheaderlist(){
      let data = {};
      apiBase.DoService(
        data,
        apiBase.getApiAdress().Column.GetVdrColumns,
        res => {
          this.headList = res.data.content;
        }
      )
    },
    // 获取厂家名称
    GetVdrType(){
        let data = {};
        apiBase.DoService(
            data,
            apiBase.getApiAdress().Code.GetVdrType,
            res => {
                this.chargeProjectTypes = res.data.content;
            }
        )
    },
    //收费项目历史价格查询
    getPriceHistory() {
      let data = {
        PageIndex: this.pageOrderLSJG.currentPage,
        PageSize: this.pageOrderLSJG.pageSize,
        OrderBy: this.pageOrderLSJG.orderType,
        OrderByType: this.pageOrderLSJG.orderSort,
        Data: { CpechaidEqual: this.currentRow.CHAID }
      };
      apiBase.DoService(
        data,
        apiBase.getApiAdress().ChargeProject.QueryPriceHistory,
        res => {
          this.dataListLSJG = res.data.content.OutData;
          this.pageOrderLSJG.totalNum = res.data.content.RecordCount;
        },
        res => {
          this.$message.error(res.data.msg);
        }
      );
    },
    //分页和排序
    pageChangeLSJG(value) {
      this.pageOrderLSJG = value;
      this.getPriceHistory();
    },
    //分页和排序
    pageChange(value) {
      this.pageOrder = value;
      this.getData();
    },
     operate(order, id) {
            this.order = order;
            // this.dataRepeat();
            switch (this.order) {
            case ADD:
                // this.title = "物品类别新增";
                // this.initSelectData();
                this.$refs.dialog.open(this.order);
                break;
            case MODIFYPROJECT:
                // this.title = "物品类别修改";
                // this.initSelectData();
                // this.dataInfo(id);
                this.$refs.dialog.open(this.order,this.currentRow.VDRID);
                break;
            case DELETE:
                this.DpgDelete(this.currentRow.VDRID);
                break;
            case INFO:
                this.$refs.dialog.open(this.order,this.currentRow.VDRID);
                break;
            case enable:
                // this.$refs.useMain.open('取消禁用', this.currentRow.VDRID);
                this.UpdateCancelDisable(this.currentRow.VDRID);
                break;
            case disable:
                // this.$refs.useMain.open(this.order, this.currentRow.VDRID);
                this.UpdateDisable(this.currentRow.VDRID);
                break;
            default:
            }
        },
    //删除
    DpgDelete(id){
        this.$confirm("确认是否删除该数据?", "提示", {
            confirmButtonText: "确定",
            cancelButtonText: "取消",
            type: "warning"
          })
          .then(callback => {
              let data = {
                VDRID: id
              };
              apiBase.DoService(
                data,
                apiBase.getApiAdress().Depot.DeleteVdr,
                res => {
                  this.getData();
                }
              );
            })
          .catch(() => {
            this.$message({
              type: "info",
              message: "已取消"
            });
          });
    },
    //禁用
    UpdateDisable(id){
        let data = {
                ID: id
              };
              apiBase.DoService(
                data,
                apiBase.getApiAdress().Status.UpdateDisable,
                res => {
                  this.getData();
                }
              );
    },
    //启用
    UpdateCancelDisable(id){
        let data = {
                ID: id
              };
              apiBase.DoService(
                data,
                apiBase.getApiAdress().Status.UpdateCancelDisable,
                res => {
                  this.getData();
                }
              );
    },
    //查询条件重置
    btnRepeat() {
      this.selectData = {};
      this.getData();
    },
    btnShow(btn) {
      let status = '';
      if(this.currentRow){
        status = this.currentRow.VDRSTATUS;
      }
      switch (btn) {
        case ADD:
          return true;
          break;
        case MODIFYPROJECT:
        case DELETE:
        case INFO:
          if(this.currentRow) return true;
          break;
        case enable:
          return status === 'B';
          break;
        case disable:
          return status === 'A';
          break;
        default:
      }
    },
    //数据重置
    dataRepeat() {
      this.chaData = {};
    },
  },
  components: {
    sweetModal,
    dataTable,
    manufactorMaintainmain,
    staEndUse
  },
  mounted() {},
  created() {
    this.getData();
    this.getheaderlist();
    this.GetVdrType();
  }
};
</script>
